package com.sftz.modules.minapp.homepage.module;

import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;

import com.sftz.framework.rersult.MobileResult;
import com.sftz.modules.minapp.homepage.form.HomePageForm;
import com.sftz.modules.minapp.homepage.service.HomePageViewServcie;
import com.sftz.modules.minapp.user.cache.RedissionUserCache;

/**
 * @author   王宏伟
 * @Date	 2017年12月29日 	 
 */
@IocBean
@At("/wx/homepage/")
public class HomePageModule {

	@Inject
	private HomePageViewServcie homePageViewServcie;

	/**
	 *	主页
	 */
	@At
	@Ok("json")
	public Object homepageData(@Param("..") final HomePageForm form) {
		return homePageViewServcie.homepage(form);
	}

	/**
	 *	首页我的-获取用户信息
	 */
	@At
	@Ok("json")
	public Object queryUserInfo(@Param("..") final HomePageForm form) {
		String token = form.getToken();
		Integer userId = RedissionUserCache.getUserId(token);
		return homePageViewServcie.queryUserInfo(userId);
	}

	/**
	 *	关注取消
	 */
	@At
	@Ok("json")
	public Object getFollowing(@Param("..") final HomePageForm form) {
		Integer id = form.getId();
		String token = form.getToken();
		Integer userId = RedissionUserCache.getUserId(token);
		Integer othersUserId = form.getOthersUserId();
		Integer status = form.getStatus();
		return homePageViewServcie.getFollowing(id, userId, othersUserId, status);
	}

	/**
	 *	用户修改签名
	 */
	@At
	@Ok("json")
	public Object updateSignature(@Param("..") final HomePageForm form) {
		String token = form.getToken();
		Integer userId = RedissionUserCache.getUserId(token);
		try {
			homePageViewServcie.updateSignature(userId, form.getSign());
			return MobileResult.success("接口调用成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return MobileResult.error("接口调用失败", null);
		}
	}

}
